<template>
    <el-form-item label="" :prop="`adgroup.delivery.${dataForm.delivery_index}.bid_price`" :rules="createRules.checkPrice">
        <el-input v-model="dataForm.adgroup.delivery[dataForm.delivery_index].bid_price" @change="sessionSave" placeholder="请输入" style="width:318px">
            <span slot="suffix" style="line-height:32px;color:#17233D;margin-right:5px">USD/点击</span>
        </el-input>
    </el-form-item>
</template>

<script>
export default {
    props: ["dataForm"],
    components: {},
    name: "",
    data() {
        var checkPrice = (rule, value, callback) => {
            let reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
            let price = Number(value)
            let max_price = Number(this.dataForm.adgroup.delivery[this.dataForm.delivery_index].budget) 
            if (!reg.test(price)) {
                return callback(new Error("请输入正确的数值"));
            } else if (price > max_price) {
                return callback(new Error("不能大于广告组预算"));
            } else {
                callback();
            }
        };
        return {
            createRules:{
                checkPrice: [
                    {required: true,message: "请输入",trigger: ["blur", "change"],},
                    { validator: checkPrice, trigger: ["blur", "change"] },
                ],
            }
        };
    },
    created() {},
    methods: {
        sessionSave(){
            this.$emit("sessionSave")
        }
    },
};
</script>


<style scoped>
</style>

